-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wp-cli integration #458
Add wp-cli integration #458
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the theme check fails, the error messages are not logged. All that is returned is:
$ wp theme-check run
Error: Theme check failed for twentytwentyfive.
Nice change! I can't push to your branch, but here is some suggestion changes to the readme: Usage with wp-cliTo use with wp-cli, ensure the theme check plugin is active and
Options
Examples
|
Co-authored-by: Jeff Ong <[email protected]>
@jffng cool, it looks good. I added you as a collaborator in the fork so you can push :) |
What a cool feature @matiasbenedetto . Thank you for this! Hope it will be in the master soon! |
wp-cli/class-theme-check-cli.php
Outdated
'result' => "Error: Theme check failed for {$check_theme_slug}.", | ||
'messages' => array(), | ||
); | ||
WP_CLI::log( wp_json_encode( $json_output, JSON_PRETTY_PRINT ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that output of log()
is discarded to STDOUT when --quiet
flag is passed. But here I think we should display JSON output whatever case if quiet flag is present or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I used line()
to log the results.
I found 2 issues regarding wp-cli loggers while working on this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But here I think we should display JSON output whatever case if quiet flag is present or not.
Not sure I agree with bypassing --quiet
, I would expect no output at all. An alternative is to make sure that the program always exits with a descriptive code; ie. 0 for OK, non-0 for errors.
edit: On reading @matiasbenedetto's comment below, seems like the checks are not meant to return a boolean.
It's a little bit counterintuitive, but the theme-check plugin doesn't work with the objective of outputting a boolean ("theme OK/ theme with errors"). The plugin is not designed like that. It just outputs a list of messages regarding the theme, but it never says whether this theme is OK or not. Maybe in the future, we could implement that, but that's not the case yet.
Still, I don't think bypassing --quiet
is cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was fixed on the latest commits.
When I run check on a theme with errors.
But when there is no errors, output includes recommendation and info items.
|
I don't know what kind of errors you are checking, but I think this is expected if the checking couldn't run. Theme-check will return an error message if the check can't be run for some reason (errors parsing theme code, for example). The success and error messages are only used to signal whether the plugin was able to run the checks or not, not to output the results of those checks.
It's a little bit counterintuitive, but the theme-check plugin doesn't work with the objective of outputting a boolean ("theme OK/ theme with errors"). The plugin is not designed like that. It just outputs a list of messages regarding the theme, but it never says whether this theme is OK or not. Maybe in the future, we could implement that, but that's not the case yet. |
Example:
Another case:
There is no right or wrong approach. We can go for any approach we agree upon. But from my experience, general expectation in CLI is that if I pass |
I see now. Yes, I agree that if we're explicitly asking for a format, it makes sense to bypass |
wp-cli/class-theme-check-cli.php
Outdated
if ( ! $success ) { | ||
WP_CLI::error( "Theme check failed for {$check_theme_slug}." ); | ||
} | ||
$this->display_themechecks_in_cli( $check_theme_slug ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Execution stops if a WP_CLI::error
is thrown, so the errors are not being displayed. Could this line be moved above the $success check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, i'm seeing this logic here:
// If the check process failed (if the checks were not able to run properly) raise an error. There's nothing else to do.
if ( ! $success ) {
WP_CLI::error( "Theme check failed for {$check_theme_slug}." );
}
// If the checking process run print in the console the checks. This will also print the things marked as an error in the theme.
$this->display_themechecks_in_cli( $check_theme_slug );
Could you explain why you think we should move it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If the check process failed (if the checks were not able to run properly) raise an error. There's nothing else to do.
I don't think this is correct. $success
is the result of run_themechecks_against_theme
which returns false
if the theme fails a check.
Could you explain why you think we should move it?
Using twentytwentyfive
, here is the output currently:
Error: Theme check failed for twentytwentyfive.
Moving call to display_themechecks_in_cli
above the conditional, the result is:
Success: Theme check completed for twentytwentyfive.
REQUIRED: phpcs.xml.dist XML file found. This file must not be in the production version of the theme.
WARNING: assets/images/image-from-rawpixel-id-2222755.webp is 997.6 KB in size. Large file sizes have a negative impact on website performance and loading time. Compress images before using them.
WARNING: assets/images/image-from-rawpixel-id-2224378.webp is 879.6 KB in size. Large file sizes have a negative impact on website performance and loading time. Compress images before using them.
WARNING: assets/images/location.webp is 778.1 KB in size. Large file sizes have a negative impact on website performance and loading time. Compress images before using them.
WARNING: assets/images/poster-image-background.webp is 574.7 KB in size. Large file sizes have a negative impact on website performance and loading time. Compress images before using them.
INFO Themes that use the tag accessibility-ready will need to undergo an accessibility review. See https://make.wordpress.org/themes/handbook/review/accessibility/
WARNING: Your theme appears to be in the wrong directory for the theme name. The directory name must match the slug of the theme. This theme's correct slug and text-domain is twenty-twenty-five. (If this is a child theme, you can ignore this error.)
INFO: Only one text-domain is being used in this theme. Make sure it matches the theme's slug correctly so that the theme will be compatible with WordPress.org language packs. The domain found is twentytwentyfive.
RECOMMENDED: Requires PHP is recommended to have major and minor versions only (e.g. 7.4). Patch version is not needed (e.g. 7.4.1).
Error: Theme check failed for twentytwentyfive.
I think the latter is more useful because it reports what checks failed (the first one marked REQUIRED
).
Also I am not sure we should throw an error here if $success
isn't true, because the theme check successfully ran, but the result was it failed the checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command's focus should be on pass/fail check for a theme, rather than run is successfully completed or not. And exit code should be returned based on that I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I could implement your feedback, please see: #458 (comment)
I went through the theme-check plugin code again, and I found that we can get a boolean signaling if the theme has required changes or not. Knowing that I was able to I implemented all the reamaining feedback (thanks you all!) on the latest commits:
These are the results using TT4 theme (I removed
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Jeff Ong <[email protected]>
What?
Add wp-cli integration for theme-check plugin
Why?
To use the output of the theme-check plugin in automated environments like CI workflows.
How to use and how to test
theme-check
plugin using this branch.wp-cli
in your system.wp theme-check run
.It should look like this:
Running
wp theme-check run
:Running
wp theme-check run --format=json
:Screencast
Screencast.from.06-09-24.11.39.55.webm